public class SleepInterrupt extends Object implements Runnable {
  public void run() {
    try {
      System.out.println("in run() - sleep for 20 seconds " + Thread.currentThread().isInterrupted());
      Thread.sleep(20000);
      System.out.println("in run() - woke up");
    } catch (InterruptedException x) {
    	Thread.currentThread().interrupt();
      System.out.println("in run() - interrupted while sleeping" + Thread.currentThread().isInterrupted());
      return;
    }
    System.out.println("in run() - leaving normally");
  }

  
  public static void main(String[] args) {
    SleepInterrupt si = new SleepInterrupt();
    Thread t = new Thread(si);
    t.start();

    // Be sure that the new thread gets a chance to
    // run for a while.
    try {
      Thread.sleep(2000);
    } catch (InterruptedException x) {
    	 System.out.println("Sleeping child ...");
    }

    System.out.println("in main() - interrupting other thread " +  t.isInterrupted());
    t.interrupt();
    System.out.println("in main() - leaving " + t.isInterrupted());
    
    try {
        Thread.sleep(2000);
      } catch (InterruptedException x) {
      	 System.out.println("Sleeping child ...");
      }
    t.interrupt();
    System.out.println("in main()2 - leaving " + t.isInterrupted());    
  }
}